import Request from '../common/js/request'
import { getAuthInfo } from '../common/js/cache'

// 认证接口
class AuthService {
  /**
   * 获取Token
   * @param account 账号、邮箱、手机号
   * @param password 密码
   */
  static getToken(account, password) {
    const url = '/api-auth/auth/getToken'

    const data = {
      account,
      password
    }

    return Request.post(url, data)
  }

  /**
   * 刷新Token
   * @param refreshToken 刷新Token
   */
  static refreshToken(refreshToken) {
    const url = '/api-auth/auth/refreshToken'

    const data = {
      refreshToken
    }

    return Request.post(url, data)
  }

  /**
   * 清除Token
   */
  static removeToken() {
    const url = '/api-auth/auth/removeToken'

    const authInfo = getAuthInfo()

    const data = {
      accessToken: authInfo.accessToken
    }

    return Request.post(url, data)
  }
}

export default AuthService
